package org.particlethink.repository.acceptance;

import org.particlethink.entry.DeliverStatus;
import org.particlethink.entry.PlanTyp;
import org.particlethink.mapper.AcceptanceMapper;
import org.particlethink.mapper.DeliverMapper;
import org.particlethink.mapper.PlanMaterialMapper;
import org.particlethink.model.Acceptance;
import org.particlethink.model.Deliver;
import org.particlethink.model.PlanMaterial;
import org.particlethink.request.DeliveryGood;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("acceptanceProjectUserImpl")
public class ProjectUserImpl {//项目用户
    @Autowired
    private AcceptanceMapper acceptanceMapper;
    @Autowired
    private DeliverMapper deliverMapper;
    @Autowired
    private PlanMaterialMapper planMaterialMapper;

    //拒签发货单
//    public void reject(int deliverId) {
//
//        Deliver deliver = this.deliverMapper.selectByPrimaryKey(deliverId);
//        if (!deliver.canReject()) {
//            return;
//        }
//
//
//        // 作废
//        deliver.setStatus(DeliverStatus.Discard);
//        deliverMapper.updateByPrimaryKeySelective(deliver);
//    }

    //验收发货单
//    public void accept(int deliverId, Acceptance acceptance, List<DeliveryGood> goods) {
//        // 发货单
//        Deliver deliver = this.deliverMapper.selectByPrimaryKey(deliverId);
//
//        // 验证权限
//        if (!deliver.canAccept()) {
//            return;
//        }
//
//        deliver.setStatus(DeliverStatus.UnConfirmed);
//        deliverMapper.updateByPrimaryKeySelective(deliver);
//
//        this.acceptanceMapper.insert(acceptance);
//
//        List<PlanMaterial> planMaterials = this.planMaterialMapper.selectByPlanIDAndTyp(deliverId, PlanTyp.Deliver);
//        Map<Integer, PlanMaterial> id2PlanMaterialMap = new HashMap<>();
//        planMaterials.forEach(planMaterial -> {
//            id2PlanMaterialMap.put(planMaterial.getId(), planMaterial);
//        });
//
//        goods.forEach(deliveryGoodsInfo -> {
//            PlanMaterial planMaterial = id2PlanMaterialMap.get(deliveryGoodsInfo.getPlanMaterialId());
//            planMaterial.setCompleteNum(deliveryGoodsInfo.getGoodsNum());
//            planMaterialMapper.updateByPrimaryKeySelective(planMaterial);
//        });
//    }


    //暂存发货单

    //撤回验收结果
    //修改验收结果
    //再次发起验收


}
